<%@ page import="BL.AccessDB"%>

<%
	HttpSession sess = request.getSession();

	String[] kat = AccessDB.getKat();
	String[] subKat;
	String selKat = request.getParameter("kategorien");
	String selSubkat = request.getParameter("subKategorien");
	if (selKat == null || selKat.equals("Neue Kategorie")) {
		subKat = null;
	} else {
		subKat = AccessDB.getSubKat(selKat);
	}
	String[][] alleKat = AccessDB.getKatANDSubKat();
%>

<h2>Kategorie verwalten:</h2>
<br>
<p>
	<b>neue Kategorie hinzuf&uumlgen:</b>
</h4>
<form method=post action="centralServlet">
	<input type="hidden" name="act" value="kategorieVerwalten"></input>
	<table>
		<tr>
			<td>Kategorie:</td>
			<td><select id="kategorien" name="kategorien"
				onchange="this.form.submit()"">
					<option>Neue Kategorie</option>
					<%
						for (int i = 0; i < kat.length; i++) {
							if (selKat != null && selKat.equals(kat[i])) {
								out.println("<option selected>" + kat[i] + "</option>");
							} else {
								out.println("<option>" + kat[i] + "</option>");
							}
						}
					%>
			</select></td>
		</tr>
		<tr>
			<td>Neue Kategorie:</td>
			<td>
				<%
					if (selKat != null && !(selKat.equals("Neue Kategorie"))) {
				%> <input type="text" name="neueKategorie" value="" disabled></input>
				<%
					} else {
				%> <input type="text" name="neueKategorie" maxlength="20"></input> <%
 	}
 %>
			</td>
		</tr>
		<tr>
			<td>Subkategorie:</td>
			<td><select id="subKategorien" name="subKategorie">
					<%
						if (subKat == null) {
					%>
					<option>(leer)</option>
					<%
						} else {
					%>
					<option>Bisherige Subkategorien</option>
					<%
						for (int i = 0; i < subKat.length; i++) {
								out.println("<option>" + subKat[i] + "</option>");
							}
						}
					%>
			</select></td>
		</tr>
		<tr>
			<td>Neue Subkategorie:</td>
			<td><input type="text" name="neueSubkategorie"></input></td>
		</tr>
	</table>
	<input type="submit" name="kategorieAct" value="Kategorie hinzufuegen" maxlength="20">
	<p>
	<p>

		<b>Kategorien in der Datenbank:</b>
	<table>
		<tr>
			<th>Kategorie</th>
			<th>Subkategorie</th>
			<th>Anz. E.</th>
			<th></th>
		</tr>
		<%
			for (int x = 0; x < alleKat.length; x++) {
				out.println("<tr><td>" + alleKat[x][0] + "</td>");
				out.println("<td>" + alleKat[x][1] + "</td>");
		%>
		<%
			int h = AccessDB.getAnzEintraege(alleKat[x][1]);
		%>
		<td><%=h%></td>
		<%
			if (h == 0) {
		%>
		<td><input type="submit" name="kategorieDeleteAct"
			value="<%=alleKat[x][1] %> loeschen"></input></td>


		<input type='hidden' name='katloeschen'></input>

		<%
			}
		%>
		</tr>
		<%
			}
		%>
	</table>
</form>
<%
	if (sess.getAttribute("fehler") != null) {
		if (sess.getAttribute("fehler") != "")
			out.print("<script>alert('" + sess.getAttribute("fehler")
					+ "');</script>");
	}
%>
